package com.onstar.cn.weight.ptr;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.onstar.cn.weight.R;


/**
 * Created by 6335yz on 2016/7/3.
 */
public class MyPtrHeader extends RelativeLayout implements PtrUIHandler {

    private TextView description,updated_at;

    public MyPtrHeader(Context context) {
        super(context);
        initView();
    }

    public MyPtrHeader(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView();
    }

    public MyPtrHeader(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView();
    }

    private void initView() {
        View header = LayoutInflater.from(getContext()).inflate(R.layout.pull_to_refresh, this);
        description = (TextView) header.findViewById(R.id.description);
        updated_at = (TextView) header.findViewById(R.id.updated_at);
    }

    @Override
    public void onUIReset(PtrFrameLayout frame) {

    }

    @Override
    public void onUIRefreshPrepare(PtrFrameLayout frame) {
        description.setText("下拉可以刷新!");
        updated_at.setText(getResources().getString(R.string.updated_at,"2天"));
    }

    @Override
    public void onUIRefreshBegin(PtrFrameLayout frame) {
        description.setText("正在刷新...");
    }

    @Override
    public void onUIRefreshComplete(PtrFrameLayout frame) {
        description.setText("完成!");
    }

    @Override
    public void onUIPositionChange(PtrFrameLayout frame, boolean isUnderTouch, byte status, PtrIndicator ptrIndicator) {

    }
}
